package com.exam.controller;

import com.exam.entity.Question;
import com.exam.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/qt")
public class QuestionRestController {

    @Autowired
    QuestionService questionService;

    @GetMapping("/all")
    public Object getAll(){
        List<Question> questions = questionService.getByQuery(null);
        return questions;
    }

    @GetMapping("/query")
    public Object getByQuery(Integer subject){
        List<Question> questions = questionService.getByQuery(subject);
        return questions;
    }

    @GetMapping("/one")
    public Object getOne(Long questionid){
        Question question = questionService.getById(questionid);
        return question;
    }

    //路径参数--有强制性
    @GetMapping("/one2/{questionid}")
    public Object getOne2(@PathVariable("questionid") Long questionid){
        Question question = questionService.getById(questionid);
        return question;
    }

    //新增
    @PostMapping("/add")
    public String add(Question question){
        questionService.add(question);
        return "ok";
    }

    @PostMapping("/update")
    public String update(Question question){
        questionService.update(question);
        return "ok";
    }
}
